package com.kancy.publicapi.aop.aspect;

public class ApiLog{
    private Long startTime;
    private Long endTime;
    private Long consumeTime;
    private String requestUrl;
    private String requestMethod;
    private String requestIp;
    private String apiClassName;
    private String apiMethodName;
    private String requestBody;
    private String responseBody;

    public static ApiLog newInstance() {
        return new ApiLog();
    }
    private ApiLog() {
        startTime = System.currentTimeMillis();
    }
    public void setEndTime(Long endTime) {
        this.endTime = endTime;
        this.consumeTime = this.endTime - this.startTime;
    }
    public void setRequestUrl(String requestUrl) {
        this.requestUrl = requestUrl;
    }
    public void setRequestMethod(String requestMethod) {
        this.requestMethod = requestMethod;
    }
    public void setRequestIp(String requestIp) {
        this.requestIp = requestIp;
    }
    public void setApiClassName(String apiClassName) {
        this.apiClassName = apiClassName;
    }
    public void setApiMethodName(String apiMethodName) {
        this.apiMethodName = apiMethodName;
    }
    public void setRequestBody(String requestBody) {
        this.requestBody = requestBody;
    }

    public void setResponseBody(String responseBody) {
        this.responseBody = responseBody;
    }

    @Override
    public String toString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append("耗时:").append(consumeTime).append("ms").append(" , ");
        buffer.append("URL:").append(requestUrl).append(" , ");
        buffer.append("IP:").append(requestIp).append(" , ");
        buffer.append("方式:").append(requestMethod).append(" , ");
        buffer.append("请求方法:").append(apiClassName).append(".").append(apiMethodName).append(" , ");
        buffer.append("\r\n");
        buffer.append("输入:").append(requestBody);
        buffer.append("\r\n");
        buffer.append("输出:").append(responseBody);
        return buffer.toString();
    }

}
